using System; 
using System.Text; 
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration; 
using System.Xml; 
using System.Xml.Serialization;
using SubSonic; 
using SubSonic.Utilities;

namespace Adex
{
	/// <summary>
	/// Strongly-typed collection for the Invoice class.
	/// </summary>
	[Serializable]
	public partial class InvoiceCollection : ActiveList<Invoice, InvoiceCollection> 
	{	   
		public InvoiceCollection() {}

	}

	/// <summary>
	/// This is an ActiveRecord class which wraps the Invoice table.
	/// </summary>
	[Serializable]
	public partial class Invoice : ActiveRecord<Invoice>
	{
		#region .ctors and Default Settings
		
		public Invoice()
		{
		  SetSQLProps();
		  InitSetDefaults();
		  MarkNew();
		}

		
		private void InitSetDefaults() { SetDefaults(); }

		
		public Invoice(bool useDatabaseDefaults)
		{
			SetSQLProps();
			if(useDatabaseDefaults)
				ForceDefaults();
			MarkNew();
		}

		public Invoice(object keyID)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByKey(keyID);
		}

		 
		public Invoice(string columnName, object columnValue)
		{
			SetSQLProps();
			InitSetDefaults();
			LoadByParam(columnName,columnValue);
		}

		
		protected static void SetSQLProps() { GetTableSchema(); }

		
		#endregion
		
		#region Schema and Query Accessor
		public static Query CreateQuery() { return new Query(Schema); }

		
		public static TableSchema.Table Schema
		{
			get
			{
				if (BaseSchema == null)
					SetSQLProps();
				return BaseSchema;
			}

		}

		
		private static void GetTableSchema() 
		{
			if(!IsSchemaInitialized)
			{
				//Schema declaration
				TableSchema.Table schema = new TableSchema.Table("Invoice", TableType.Table, DataService.GetInstance("Adex"));
				schema.Columns = new TableSchema.TableColumnCollection();
				schema.SchemaName = @"dbo";
				//columns
				
				TableSchema.TableColumn colvarInvoiceID = new TableSchema.TableColumn(schema);
				colvarInvoiceID.ColumnName = "InvoiceID";
				colvarInvoiceID.DataType = DbType.Int32;
				colvarInvoiceID.MaxLength = 0;
				colvarInvoiceID.AutoIncrement = true;
				colvarInvoiceID.IsNullable = false;
				colvarInvoiceID.IsPrimaryKey = true;
				colvarInvoiceID.IsForeignKey = false;
				colvarInvoiceID.IsReadOnly = false;
				colvarInvoiceID.DefaultSetting = @"";
				colvarInvoiceID.ForeignKeyTableName = "";
				schema.Columns.Add(colvarInvoiceID);
				
				TableSchema.TableColumn colvarUserID = new TableSchema.TableColumn(schema);
				colvarUserID.ColumnName = "UserID";
				colvarUserID.DataType = DbType.Int32;
				colvarUserID.MaxLength = 0;
				colvarUserID.AutoIncrement = false;
				colvarUserID.IsNullable = true;
				colvarUserID.IsPrimaryKey = false;
				colvarUserID.IsForeignKey = false;
				colvarUserID.IsReadOnly = false;
				colvarUserID.DefaultSetting = @"";
				colvarUserID.ForeignKeyTableName = "";
				schema.Columns.Add(colvarUserID);
				
				TableSchema.TableColumn colvarUserFullName = new TableSchema.TableColumn(schema);
				colvarUserFullName.ColumnName = "UserFullName";
				colvarUserFullName.DataType = DbType.String;
				colvarUserFullName.MaxLength = 100;
				colvarUserFullName.AutoIncrement = false;
				colvarUserFullName.IsNullable = true;
				colvarUserFullName.IsPrimaryKey = false;
				colvarUserFullName.IsForeignKey = false;
				colvarUserFullName.IsReadOnly = false;
				colvarUserFullName.DefaultSetting = @"";
				colvarUserFullName.ForeignKeyTableName = "";
				schema.Columns.Add(colvarUserFullName);
				
				TableSchema.TableColumn colvarUserEmail = new TableSchema.TableColumn(schema);
				colvarUserEmail.ColumnName = "UserEmail";
				colvarUserEmail.DataType = DbType.String;
				colvarUserEmail.MaxLength = 100;
				colvarUserEmail.AutoIncrement = false;
				colvarUserEmail.IsNullable = true;
				colvarUserEmail.IsPrimaryKey = false;
				colvarUserEmail.IsForeignKey = false;
				colvarUserEmail.IsReadOnly = false;
				colvarUserEmail.DefaultSetting = @"";
				colvarUserEmail.ForeignKeyTableName = "";
				schema.Columns.Add(colvarUserEmail);
				
				TableSchema.TableColumn colvarCompanyCode = new TableSchema.TableColumn(schema);
				colvarCompanyCode.ColumnName = "CompanyCode";
				colvarCompanyCode.DataType = DbType.Int32;
				colvarCompanyCode.MaxLength = 0;
				colvarCompanyCode.AutoIncrement = false;
				colvarCompanyCode.IsNullable = true;
				colvarCompanyCode.IsPrimaryKey = false;
				colvarCompanyCode.IsForeignKey = false;
				colvarCompanyCode.IsReadOnly = false;
				colvarCompanyCode.DefaultSetting = @"";
				colvarCompanyCode.ForeignKeyTableName = "";
				schema.Columns.Add(colvarCompanyCode);
				
				TableSchema.TableColumn colvarCompanyName = new TableSchema.TableColumn(schema);
				colvarCompanyName.ColumnName = "CompanyName";
				colvarCompanyName.DataType = DbType.String;
				colvarCompanyName.MaxLength = 200;
				colvarCompanyName.AutoIncrement = false;
				colvarCompanyName.IsNullable = true;
				colvarCompanyName.IsPrimaryKey = false;
				colvarCompanyName.IsForeignKey = false;
				colvarCompanyName.IsReadOnly = false;
				colvarCompanyName.DefaultSetting = @"";
				colvarCompanyName.ForeignKeyTableName = "";
				schema.Columns.Add(colvarCompanyName);
				
				TableSchema.TableColumn colvarInvoiceDate = new TableSchema.TableColumn(schema);
				colvarInvoiceDate.ColumnName = "InvoiceDate";
				colvarInvoiceDate.DataType = DbType.DateTime;
				colvarInvoiceDate.MaxLength = 0;
				colvarInvoiceDate.AutoIncrement = false;
				colvarInvoiceDate.IsNullable = true;
				colvarInvoiceDate.IsPrimaryKey = false;
				colvarInvoiceDate.IsForeignKey = false;
				colvarInvoiceDate.IsReadOnly = false;
				colvarInvoiceDate.DefaultSetting = @"";
				colvarInvoiceDate.ForeignKeyTableName = "";
				schema.Columns.Add(colvarInvoiceDate);
				
				TableSchema.TableColumn colvarOrderID = new TableSchema.TableColumn(schema);
				colvarOrderID.ColumnName = "OrderID";
				colvarOrderID.DataType = DbType.Int32;
				colvarOrderID.MaxLength = 0;
				colvarOrderID.AutoIncrement = false;
				colvarOrderID.IsNullable = true;
				colvarOrderID.IsPrimaryKey = false;
				colvarOrderID.IsForeignKey = false;
				colvarOrderID.IsReadOnly = false;
				colvarOrderID.DefaultSetting = @"";
				colvarOrderID.ForeignKeyTableName = "";
				schema.Columns.Add(colvarOrderID);
				
				TableSchema.TableColumn colvarTotalAmount = new TableSchema.TableColumn(schema);
				colvarTotalAmount.ColumnName = "TotalAmount";
				colvarTotalAmount.DataType = DbType.Currency;
				colvarTotalAmount.MaxLength = 0;
				colvarTotalAmount.AutoIncrement = false;
				colvarTotalAmount.IsNullable = true;
				colvarTotalAmount.IsPrimaryKey = false;
				colvarTotalAmount.IsForeignKey = false;
				colvarTotalAmount.IsReadOnly = false;
				colvarTotalAmount.DefaultSetting = @"";
				colvarTotalAmount.ForeignKeyTableName = "";
				schema.Columns.Add(colvarTotalAmount);
				
				TableSchema.TableColumn colvarDateAdded = new TableSchema.TableColumn(schema);
				colvarDateAdded.ColumnName = "DateAdded";
				colvarDateAdded.DataType = DbType.DateTime;
				colvarDateAdded.MaxLength = 0;
				colvarDateAdded.AutoIncrement = false;
				colvarDateAdded.IsNullable = false;
				colvarDateAdded.IsPrimaryKey = false;
				colvarDateAdded.IsForeignKey = false;
				colvarDateAdded.IsReadOnly = false;
				
						colvarDateAdded.DefaultSetting = @"(getdate())";
				colvarDateAdded.ForeignKeyTableName = "";
				schema.Columns.Add(colvarDateAdded);
				
				TableSchema.TableColumn colvarDateModified = new TableSchema.TableColumn(schema);
				colvarDateModified.ColumnName = "DateModified";
				colvarDateModified.DataType = DbType.DateTime;
				colvarDateModified.MaxLength = 0;
				colvarDateModified.AutoIncrement = false;
				colvarDateModified.IsNullable = false;
				colvarDateModified.IsPrimaryKey = false;
				colvarDateModified.IsForeignKey = false;
				colvarDateModified.IsReadOnly = false;
				
						colvarDateModified.DefaultSetting = @"(getdate())";
				colvarDateModified.ForeignKeyTableName = "";
				schema.Columns.Add(colvarDateModified);
				
				BaseSchema = schema;
				//add this schema to the provider
				//so we can query it later
				DataService.Providers["Adex"].AddSchema("Invoice",schema);
			}

		}

		#endregion
		
		#region Props
		
		  
		[XmlAttribute("InvoiceID")]
		public int InvoiceID 
		{
			get { return GetColumnValue<int>("InvoiceID"); }

			set { SetColumnValue("InvoiceID", value); }

		}

		  
		[XmlAttribute("UserID")]
		public int? UserID 
		{
			get { return GetColumnValue<int?>("UserID"); }

			set { SetColumnValue("UserID", value); }

		}

		  
		[XmlAttribute("UserFullName")]
		public string UserFullName 
		{
			get { return GetColumnValue<string>("UserFullName"); }

			set { SetColumnValue("UserFullName", value); }

		}

		  
		[XmlAttribute("UserEmail")]
		public string UserEmail 
		{
			get { return GetColumnValue<string>("UserEmail"); }

			set { SetColumnValue("UserEmail", value); }

		}

		  
		[XmlAttribute("CompanyCode")]
		public int? CompanyCode 
		{
			get { return GetColumnValue<int?>("CompanyCode"); }

			set { SetColumnValue("CompanyCode", value); }

		}

		  
		[XmlAttribute("CompanyName")]
		public string CompanyName 
		{
			get { return GetColumnValue<string>("CompanyName"); }

			set { SetColumnValue("CompanyName", value); }

		}

		  
		[XmlAttribute("InvoiceDate")]
		public DateTime? InvoiceDate 
		{
			get { return GetColumnValue<DateTime?>("InvoiceDate"); }

			set { SetColumnValue("InvoiceDate", value); }

		}

		  
		[XmlAttribute("OrderID")]
		public int? OrderID 
		{
			get { return GetColumnValue<int?>("OrderID"); }

			set { SetColumnValue("OrderID", value); }

		}

		  
		[XmlAttribute("TotalAmount")]
		public decimal? TotalAmount 
		{
			get { return GetColumnValue<decimal?>("TotalAmount"); }

			set { SetColumnValue("TotalAmount", value); }

		}

		  
		[XmlAttribute("DateAdded")]
		public DateTime DateAdded 
		{
			get { return GetColumnValue<DateTime>("DateAdded"); }

			set { SetColumnValue("DateAdded", value); }

		}

		  
		[XmlAttribute("DateModified")]
		public DateTime DateModified 
		{
			get { return GetColumnValue<DateTime>("DateModified"); }

			set { SetColumnValue("DateModified", value); }

		}

		
		#endregion
		
		
			
		
		//no foreign key tables defined (0)
		
		
		
		//no ManyToMany tables defined (0)
		
		#region ObjectDataSource support
		
		
		/// <summary>
		/// Inserts a record, can be used with the Object Data Source
		/// </summary>
		public static void Insert(int? varUserID,string varUserFullName,string varUserEmail,int? varCompanyCode,string varCompanyName,DateTime? varInvoiceDate,int? varOrderID,decimal? varTotalAmount,DateTime varDateAdded,DateTime varDateModified)
		{
			Invoice item = new Invoice();
			
			item.UserID = varUserID;
			
			item.UserFullName = varUserFullName;
			
			item.UserEmail = varUserEmail;
			
			item.CompanyCode = varCompanyCode;
			
			item.CompanyName = varCompanyName;
			
			item.InvoiceDate = varInvoiceDate;
			
			item.OrderID = varOrderID;
			
			item.TotalAmount = varTotalAmount;
			
			item.DateAdded = varDateAdded;
			
			item.DateModified = varDateModified;
			
		
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}

		
		/// <summary>
		/// Updates a record, can be used with the Object Data Source
		/// </summary>
		public static void Update(int varInvoiceID,int? varUserID,string varUserFullName,string varUserEmail,int? varCompanyCode,string varCompanyName,DateTime? varInvoiceDate,int? varOrderID,decimal? varTotalAmount,DateTime varDateAdded,DateTime varDateModified)
		{
			Invoice item = new Invoice();
			
				item.InvoiceID = varInvoiceID;
				
				item.UserID = varUserID;
				
				item.UserFullName = varUserFullName;
				
				item.UserEmail = varUserEmail;
				
				item.CompanyCode = varCompanyCode;
				
				item.CompanyName = varCompanyName;
				
				item.InvoiceDate = varInvoiceDate;
				
				item.OrderID = varOrderID;
				
				item.TotalAmount = varTotalAmount;
				
				item.DateAdded = varDateAdded;
				
				item.DateModified = varDateModified;
				
			item.IsNew = false;
			if (System.Web.HttpContext.Current != null)
				item.Save(System.Web.HttpContext.Current.User.Identity.Name);
			else
				item.Save(System.Threading.Thread.CurrentPrincipal.Identity.Name);
		}

		#endregion
		#region Columns Struct
		public struct Columns
		{
			 public static string InvoiceID = @"InvoiceID";
			 public static string UserID = @"UserID";
			 public static string UserFullName = @"UserFullName";
			 public static string UserEmail = @"UserEmail";
			 public static string CompanyCode = @"CompanyCode";
			 public static string CompanyName = @"CompanyName";
			 public static string InvoiceDate = @"InvoiceDate";
			 public static string OrderID = @"OrderID";
			 public static string TotalAmount = @"TotalAmount";
			 public static string DateAdded = @"DateAdded";
			 public static string DateModified = @"DateModified";
						
		}

		#endregion
	}

}

